package week3;

import java.util.*;

public class Day3 {
    public static void main1(String[] args) {
        Scanner in = new Scanner(System.in);
        // 注意 hasNext 和 hasNextLine 的区别
        while (in.hasNextInt()) { // 注意 while 处理多个 case
            double n = in.nextLong();
            long tmp = (long)Math.sqrt(n);
            double[] arr1 = {(tmp-1)*(tmp-1),tmp*tmp,(tmp+1)*(tmp+1)};
            double[] arr2 = {Math.abs(arr1[0]-n),Math.abs(arr1[1]-n),Math.abs(arr1[2]-n)};
            int k = 0;
            for(int i=1;i<3;i++) {
                if(arr2[i]<arr2[i-1]) k=i;
            }
            System.out.printf("%.0f",arr1[k]);
        }
    }

    public static void main3(String[] args) {
        PriorityQueue<int[][]> q = new PriorityQueue<>(new Comparator<int[][]>() {
            @Override
            public int compare(int[][] o1, int[][] o2) {
                return o2[0][0] - o1[0][0];
            }
        });
        int[][] arr = {{1},{2}};
        int[][] arr2 = {{2},{3}};
        q.add(arr);
        q.add(arr2);
        System.out.println();
    }
    public static void main(String[] args) {
        Scanner in = new Scanner(System.in);
        // 注意 hasNext 和 hasNextLine 的区别
        while (in.hasNextInt()) { // 注意 while 处理多个 case
            int n = in.nextInt();
            int m = in.nextInt();

            //用来记录声部组数
            PriorityQueue<Long> queue = new PriorityQueue<>(new Comparator<Long>() {
                @Override
                public int compare(Long o1, Long o2) {
                    return (int) (o2 - o1);
                }
            });
            //记录个声部的人数
            int[] nums = new int[n];
            int[] map = new int[100001];
            for(int i=0;i<n;i++) {
                nums[i]=in.nextInt();
                map[nums[i]]++;
            }
            //将各声部的人数作为一组填入队列中
            for(int i=0;i<100001;i++) {
                if(map[i]!=0) queue.add((long)map[i]);
            }
            //判断
            if(queue.size() > m) {
                System.out.println("-1");
            }else if(n==m){
                System.out.println(1);
            }else {
                while(queue.size() < m) {
                    long tmp = queue.poll();
                    long x = tmp - tmp/2;
                    long y = tmp - x;
                    queue.add(x);
                    queue.add(y);
                }
                System.out.println(queue.peek());
            }
        }
    }






}
